package com.zhouchb.blog.service.impl;

import com.zhouchb.blog.bean.Tag;
import com.zhouchb.blog.dao.TagRepositary;
import com.zhouchb.blog.service.TagsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author Zhouchb
 * @Create 2021-09-2021/9/6 :20:25
 * @Description
 */
@Service
public class TagServicImpl implements TagsService {
    @Autowired
    private TagRepositary tagRepositary;

    @Transactional(rollbackFor = {Exception.class})
    @Override
    public int saveTagesService(Tag tag) {
        return tagRepositary.saveTagesDao(tag);
    }

    @Override
    public Tag getTagByIdService(Long id) {
        return tagRepositary.getTagByIdDao(id);
    }

    @Override
    public List<Tag> listTagService() {
        return tagRepositary.listTagDao();
    }

    @Override
    public Tag getTagByNameService(String name) {
        return tagRepositary.getTagByNameDao(name);
    }

    @Override
    public List<Tag> listOrderCount(Integer size) {
        return tagRepositary.listOrderCount(size);
    }

    @Override
    public List<Tag> listTagbyBlogIdService(Long blogId) {
        return tagRepositary.listTagbyBlogId(blogId);
    }

    @Override
    public List<Tag> listTagAndCountService() {
        List<Tag> tags = tagRepositary.listTagAndCount();
        if (tags.size()==0) {
            return null;
        }
        return tags;
    }


    @Transactional
    @Override
    public int updateTagService(Long id, Tag tag) {
        return tagRepositary.updateTagDao(id, tag);
    }

    @Transactional
    @Override
    public int delTagService(Long id) {
      return   tagRepositary.delTagDao(id);
    }
}
